/*
 * NodeServer.java
 *
 * Copyright 2012 the original author or authors(ninglong).
 *
 * Licensed under the testMina, Version 1.0 (the "License");
 *
 */
package org.geek.mina.client;

import java.net.InetSocketAddress;
import java.nio.charset.Charset;

import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.transport.socket.nio.NioSocketConnector;

/**   
 * <p><客户端/p>
 * @author ninglong bhd2973@qq.com   
 * @date May 2, 2012 10:27:05 PM
 * @version V1.0   
 */
public class NodeServer {

	public static void main(String[] args) {
		//创建一个tcp/ip 的connector
		NioSocketConnector connector = new NioSocketConnector();
		//创建接收数据的过滤器
		DefaultIoFilterChainBuilder chain = connector.getFilterChain();
		chain.addLast("mychain", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName( "UTF-8"))));
		//设置消息处理器
		connector.setHandler(new ClientServer());
		//设置接收超时
		connector.setConnectTimeoutCheckInterval(30);
		//连接到服务器
		ConnectFuture cf = connector.connect(new InetSocketAddress("localhost",8080));
		
		cf.awaitUninterruptibly();
		cf.getSession().getCloseFuture().awaitUninterruptibly();
		connector.dispose();
	}

}
